/*
 * @Author: your name
 * @Date: 2024-05-27 
 * @LastEditTime: 2024-06-06 
 * @LastEditors: 杨世豪
 * @Description: In User Settings Edit
 * @FilePath: \src\api\index.js
 */

function Layer(map) {
    this.map = map;
}

Layer.prototype.addLayer = function(layer) {
    this.map.addLayer(layer);
    return layer;
};

Layer.prototype.getLayers = function() {
    return this.map.getLayers();
}

//根据图层名称删除图层
Layer.prototype.removeByLayerName = function(layerName) {
    // 获取地图上的所有图层
    let layers = this.map.getLayers();
    // 遍历图层查找目标图层
    layers.forEach(function(layer) {
        if (layer.type === "VECTOR" && layer.get('name') !== undefined && layer.get('name') === layerName) {
            // 找到目标图层，进行删除操作
            this.map.removeLayer(layer);
        }
    });
}

export default Layer;